package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingPlanDto;
import com.zzyl.service.NursingPlanService;
import com.zzyl.vo.NursingVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static com.zzyl.base.ResponseResult.success;

@RestController
@RequestMapping("/nursing/plan")
@Api(tags = "护理计划管理")
public class NursingPlanController {
    @Autowired
    private NursingPlanService nursingService;

    @GetMapping
    @ApiOperation(value = "查询所有护理计划")
    public ResponseResult<List<NursingVo>> findAll() {
        List<NursingVo> nursings = nursingService.findAll();
        return success(nursings);
    }

    @PostMapping
    @ApiOperation(value = "新增护理计划")
    public ResponseResult add(@RequestBody NursingPlanDto dto) {
        nursingService.add(dto);
        return success();
    }

    @GetMapping("/search")
    @ApiOperation(value = "分页查询护理计划")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "页码", required = true, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "每页数量", required = true, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "name", value = "护理计划名称", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "status", value = "状态", required = false, dataType = "int", paramType = "query"),
    })
    public ResponseResult<PageResponse<NursingVo>> selectByPage(Integer pageNum,
                                                                 Integer pageSize,
                                                                 String name,
                                                                 Integer status) {
        PageResponse<NursingVo> pageInfo = nursingService.selectByPage(pageNum, pageSize, name, status);
        return success(pageInfo);
    }
}
